package com.xinzhitong.www.controller;


import com.xinzhitong.www.enumeration.CollectionType;
import com.xinzhitong.www.exception.collection.CollectionNotExistException;
import com.xinzhitong.www.service.ShareService;
import com.xinzhitong.www.utils.Message;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 分享控制器
 *
 * @author 吴展鹏
 */
@CrossOrigin
@RestController
@RequestMapping("share")
public class ShareController {

    @Resource
    private ShareService shareService;


    /**
     * 分享一个链接
     *
     * @param shareId   分享类型id（委培or招聘or培训课次）
     * @param shareType 分享链接的类型（委培or招聘or培训课次）
     * @return 响应信息
     */
    @RequestMapping(value = "aShare", method = RequestMethod.PUT)
    public Message aCollection(
            @RequestParam("shareId") Integer shareId,
            @RequestParam("shareType") CollectionType shareType
    ) {
        String msg = "分享成功！";
        try {
            shareService.addAShare(shareId,shareType);
            return Message.createSuc(msg);
        } catch (CollectionNotExistException e) {
            e.printStackTrace();
            msg = "分享失效";
        }
        return Message.createErr(msg);
    }

}
